package edu.cuit.campus.admin.service.bean;

import edu.cuit.campus.admin.service.AdministratorService;
import edu.cuit.campus.commons.StringUtils;
import edu.cuit.campus.entity.po.Administrator;
import edu.cuit.campus.repository.common.MybatisHelper;
import edu.cuit.campus.repository.mapper.AdministratorMapper;

/**
 * @author <a href="mailto:1020zhaodan@163.com">Adan</a>
 * @version 1.0
 * @date 2025/8/11 16:14
 */
public class AdministratorServiceBean implements AdministratorService {
    @Override
    public Administrator login(String username, String password) {
        var session = MybatisHelper.openSession();
        var mapper = session.getMapper(AdministratorMapper.class);
        var admin = mapper.findByUsername(username);
        MybatisHelper.close();
        if(admin != null && StringUtils.check(password, admin.getPassword()))
            return admin;
        return null;
    }
}
